
var app = getApp();
Page({
  data: {
    classifyInsurance: 3,
    nowDate: '',
    startDate: '',
    returnDate: '',
    peoples: 1
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数

  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
    var myDate = new Date();
    myDate.getTime();
    var nowDate=  app.dateFormat(myDate.getTime());
    this.setData({
      nowDate: nowDate,
      startDate: nowDate,
      returnDate: nowDate

    })
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  onShareAppMessage: function () {
    return {
      title: '搜保',
      desc: '搜保户外运动险精准搜索页',
      path: '/pages/search/sport_insurance/index'
    }
  },
  sportSearch: function(e) {
    this.setData({
      keyword: e.detail.value
    })
  },
  sportPeople: function(e) {
    this.setData({
      peoples: e.detail.value
    })
  },
  startDateChange: function(e) {
    var days = app.getDateDiff(this.startDate,this.returnDate);
    this.setData({
      startDate: e.detail.value
    })
  },
  returnDateChange: function(e) {

    this.setData({
      returnDate: e.detail.value
    })
  },
  doSubmitSearch: function (){
    var that = this;
    var days = app.getDateDiff(this.data.startDate,this.data.returnDate);
    var classifyInsurance = that.data.classifyInsurance;
    var keywordSearch = that.data.keyword;
    var peoples = that.data.peoples;
    var dateStart = that.data.startDate;
    var dateEnd = that.data.returnDate;
    that.setData({
      peoples: peoples
    });
    if(keywordSearch){
      that.setData({
        searchKw: keywordSearch
      });
      wx.navigateTo({ url: '/pages/product/index/index?keyword='+ keywordSearch +'&classify='+ classifyInsurance +'&dateStart='+ dateStart +'&dateEnd='+ dateEnd +'&days='+ days  +'&peoples='+ peoples +'' });
    }else{
      wx.showModal({
        title: '提示',
        content: '请输入运动名称!',
        showCancel: false,
        success: function(res) {
          if (res.confirm) {

          }
        }
      })
    }
  }
})